﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogicUniversityBiz;

namespace LogicUniversity.clerks
{
  public partial class RequisitionList : System.Web.UI.Page
    {


      protected void Page_PreInit(Object sender, EventArgs e)
      {
          //(Session["Role"]
          if (Session["Role"] as string != "Clerk")
          {
              Response.Redirect("~/Login.aspx");
          }

      }

        RequisitionController reqController = new RequisitionController();
        Dictionary<string, string> resultValues = new Dictionary<string, string>();
        private string departmentCode;
        public string DepartmentCode
        {
            get
            {
                return departmentCode;
            }
            set
            {
                departmentCode = value;
            }
        }
        private DateTime retrievalDateParameter;

        public DateTime RetrievalDateParameter
        {
            get { return retrievalDateParameter; }
            set { retrievalDateParameter = value; }
        }
      protected void Page_Load(object sender, EventArgs e)
        {

            retrievalDateParameter = DateTime.Now;
            var result = reqController.getRequisitionList(retrievalDateParameter);
           
            foreach (Requisition req in result)
            {
                //Department department = new Department();
                //department = reqController.getDepartmentByID(req.Dept_Code);
                if (resultValues.Keys.Contains(req.Dept_Code))
                {
                    continue;
                }
               
                resultValues.Add(req.Dept_Code,((DateTime)req.Approved_Date).ToShortDateString());
            }
            if (resultValues == null || resultValues.Count <= 0)
            {
                lblMsg.Text = "Currently No Requisitions.";
            }
            else
            {
                grdRequisitionList.DataSource = resultValues;
                grdRequisitionList.DataBind();
            }
        }

      protected void grdRequisitionList_RowCommand(object sender, GridViewCommandEventArgs e)
      {
          if (e.CommandName == "Process")
          {
              int row =Convert.ToInt32(e.CommandArgument);
              DepartmentCode = grdRequisitionList.Rows[row].Cells[0].Text;
              Server.Transfer("ProcessDetail.aspx");
          }
      }
    }
}